clear all

********************************************************************
/* Convert EPS files to PDF for the LaTex wrapper */ 
cd "${individ_figs}"
	
	local pdf: dir "." files "*.eps"
	foreach f in `pdf'{
		if strpos("`f'", "map"){
			* the maptile package formats the legend using '?' instead of '-' to separate values when saving to .eps
			* we fix this below 
			shell sed -E -i.bak 's/([0-9]+)\?([0-9]+)/\1-\2/g' `f'
		}
		* On most computers, .eps files can be inserted directly into LaTeX documents --- LaTeX will convert to .pdf automatically using epstopdf
		* However epstopdf is not currently available at the Census. We therefore do the conversion manually. 
		shell ps2pdf14 -dEPSCrop -r3000 `f'
	}
	capture shell rm *.bak

********************************************************************

cd "${figures}"

********************************************************************
*** Figure 1: Physician Earnings over the Lifecyle and by Firm Size

	texdoc init "figs_earnings_lifecycle.tex", replace
	/*tex	
	\begin{landscape}
	\begin{figure}[ht]
		\centering
		\caption{\bf Physician Earnings over the Lifecycle and by Firm Size} \label{fig:lifecycle} 
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:lifecycle_ptotinc} Individual Total Income}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc03-lifecycle_ptotinc_2017.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:lifecycle_business} Contribution of Business Income}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc03-lifecycle_ptotinc_vs_w2wgs.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:lifecycle_acs_vs_tax} Administrative vs. Survey Data}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc03-lifecycle_ptotinc_vs_income_acs.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:income_vs_firmsize} Individual Total Income vs. Firm Size}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc08-income_vs_einsize_under100_age40to55_panel.pdf}
	\end{subfigure}

	\end{figure}
	\end{landscape}
	tex*/ 

********************************************************************
*** Figure 2: Correlates of Specialty Income 

	texdoc init "figs_specialty_income_correlates.tex", replace 
	/*tex
	\begin{landscape}
	\begin{figure}[ht]
		\centering
		\caption{\bf Correlates of Specialty Income} \label{fig:specialty_income_correlates} 
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:income_specialty_vs_hours} Income vs.~Hours of Work}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc05-income_vs_hours_cms_specage4055.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:income_specialty_vs_training} Income vs.~Length of Training}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc05-income_vs_resdur_allyrs_cms_specage4055.pdf}
	\end{subfigure}	
	\vspace{-10pt}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:income_specialty_vs_publications} Income vs.~Applicants' Research Experience}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc05-income_vs_publications_age40to55.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:share_graduates_vs_income_specialty}  U.S. Degree vs.~Income $\vert$ Hours, Training}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc05-us_md_share_vs_income_nrmp_spec40to55.pdf}
	\end{subfigure}

	\end{figure}
	\end{landscape}
	tex*/
	texdoc close 

********************************************************************
*** Figure 3: Geographic Variation in Earnings (State maps)

	texdoc init "figs_state_maps.tex", replace 
	/*tex
	\begin{figure}[ht]
		\centering
		\caption{\bf Geographic Variation in Earnings} \label{fig:statemaps} 
	\begin{subfigure}{0.8\linewidth}
		\caption{\label{fig:maps_statelevel_physicians} Physicians}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc09-map_ptotinc_state_physicians.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.8\linewidth}
		\caption{\label{fig:maps_statelevel_lawyers} Lawyers}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc09-map_ptotinc_state_lawyers.pdf}
	\end{subfigure}
	
	\end{figure}
	tex*/
	texdoc close 

**********************************************************************
*** Figure 4: Event Study: Physician Movers (all physicians) 

	texdoc init "figs_geotwfeeventstudy_physicians", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:geotwfeeventstudy_physicians} \bf Event Study: Physician Movers}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/geotwfe01-eventstudy_ALL.pdf}
	\end{figure}
	tex*/
	texdoc close 

*******************************************************************
*** Figure 5: Place vs. Physician Contributions to Earnings

	texdoc init "figs_twfevariance_decomposition", replace 
	/*tex
	\begin{landscape}
	\begin{figure}[ht]
		\centering
		\caption{\bf Place vs. Physician Contributions to Earnings} \label{fig:twfe_variance_decomposition} 
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:twfe_variance_decomposition_physician} Variance Decomposition: Physicians}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe02-earnings_variance_decomp_physicians.pdf}
	\end{subfigure}    
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:twfe_variance_decomposition_lawyer} Variance Decomposition: Lawyers}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe02-earnings_variance_decomp_lawyers.pdf}
	\end{subfigure}	
	\vspace{-10pt}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:binscatter_geosorting21} Place vs.~Person Effects (Person-Level)}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe11-Corr_IDFEs_hdfePLACE.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:binscatter_geosorting22} Place vs.~Person Effects (CZ-Level)}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe11-Corr_MEANIDFEs_hdfePLACE.pdf}
	\end{subfigure}

	\end{figure}
	\end{landscape}
	tex*/

	texdoc close 

*******************************************************************
*** Figure 6: Correlates of Place Effects 

	texdoc init "figs_coefplot_czcorrelates", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:coefplotczcharacterisitcs} \bf Correlates of Place Effects}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/geotwfe09-cz_correlations.pdf}
	\end{figure}
	tex*/ 
	texdoc close

********************************************************************
*** Figure 7: Effect of ACA Insurance Expansion 

	texdoc init "figs_coefplots_aca", replace 
	/*tex
	\begin{landscape}
	\begin{figure}[ht]
		\centering
		\caption{\bf Effect of ACA Insurance Expansion} \label{fig:coefplot_aca} 
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:aca:coverage} First Stage: Share Insured}
		\includegraphics[width=\linewidth]{../figures/individ_figs/govtpolicy02-ACA_eventstudy_FS.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:aca:earnings} Individual Total Income}
		\includegraphics[width=\linewidth]{../figures/individ_figs/govtpolicy02-ACA_eventstudy_logptotinc.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:aca:retirement} Retirement}
	\includegraphics[width=\linewidth]{../figures/individ_figs/govtpolicy02-ACA_eventstudy_retired_1099ssa.pdf}
	\end{subfigure}

	\end{figure}
	\end{landscape}
	tex*/
	texdoc close 

********************************************************************
*** Figure 8: Location Effects vs. Implicit Subsidies

	texdoc init "figs_fe_cz_gaf_diff", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:figs_fe_cz_gaff_diff} \bf Location Effects vs. Implicit Subsidies}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/govtpolicy01-binscatter_fe_cz_gaf_diff.pdf}
	\end{figure}
	tex*/
	texdoc close

********************************************************************************
*** Figure 9: Increase Internal Medicine Medicare Payments to Dermatology Level

	texdoc init "figs_counterfactuals_imsameasderm.tex", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:cf_stpdfcore_spec5_imsameasderm_rf} \bf Increase Internal Medicine Medicare Payments to Dermatology Level (Reduced Form)}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/counterfactuals_imsameasderm.pdf}
	\end{figure}
	tex*/
	texdoc close

********************************************************************************
*** Figure E.1 Distribution of Physician Income

	texdoc init "figs_hist_logearnings", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:hist_logearnings} \bf Distribution of Physician Income}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/desc02-kden_logptotinc1to99_2017.pdf}
	\end{figure}
	tex*/
	texdoc close 

	texdoc init "figs_hist_logaginc", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:hist_logaginc} \bf Distribution of Physician Adjusted Gross Income}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/desc02-kden_logaginc1to99_2017.pdf}
	\end{figure}
	tex*/
	texdoc close 

*****************************************************************************
*** Figure E.3: Time Series of Earnings and Firm Size 

	texdoc init "figs_timeseries", replace 
	/*tex
	\begin{landscape}
	\begin{figure}[ht]
		\centering
		\caption{\bf Time Series of Earnings and Firm Size} \label{fig:timeseries_income_firmsize} 
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:timeseries_income} Individual Total Income}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc07-time_series_ptotinc.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:timeseries_top1} Physicians in Top 1\% AGI Households}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc07-time_series_top1.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:timeseries_ein1} Physicians in EINs of Size = 1}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc08-time_series_einsize.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:timeseries_einsizemissing} Physicians with Missing Firm Size}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc08-time_series_einsize_missing.pdf}
	\end{subfigure}

	\end{figure}
	\end{landscape}
	tex*/
	texdoc close 

******************************************************************************
*** Figure E.4: Physician Labor Supply over the Lifecyle 

	texdoc init "figs_laborsupply_lifecycle", replace 
	/*tex
	\begin{landscape}
	\begin{figure}[ht]
		\centering
		\caption{\bf Physician Labor Supply over the Lifecycle} \label{fig:lifecyclelaborsupply} 
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:lifecycle_wkh} Weekly Work Hours}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc03-lifecycle_wkh_imputed_2017.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:lifecycle_retired} Retirement}
	\includegraphics[width=\linewidth]{../figures/individ_figs/desc03-lifecycle_received_1099ssa_2017.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:lifecycle_schedule_c_flag} Filed Schedule C}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc03-lifecycle_schedule_c_flag_2017.pdf}
	\end{subfigure}

	\end{figure}
	\end{landscape}
	tex*/
	texdoc close 

******************************************************************************
*** Figure E.5: Medical School Rank vs. Speciality Income 

	*** Share of Top Graduates vs. Hourly Earnings (Figure XX)
	texdoc init "figs_top5_spec_hourlyinc", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:top5_spec_hourlyinc} \bf Medical School Rank vs.~Specialty Income}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/baseline-06-individual_level_top_school_share_and_income_by_specialty.pdf}
	\end{figure}
	tex*/
	texdoc close 

******************************************************************************
*** Figure E.6: Geographic Variation in Earnings (CZ Maps)

	texdoc init "figs_cz_maps", replace 
	/*tex
	\begin{figure}[ht]
		\centering
		\caption{\bf Geographic Variation in Earnings} \label{fig:czmaps} 
	\begin{subfigure}{0.8\linewidth}
		\caption{\label{fig:maps_czlevel_physicians} Physicians}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc09-map_ptotinc_cz90imputed_physicians.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.8\linewidth}
		\caption{\label{fig:maps_czlevel_lawyers} Lawyers}
		\includegraphics[width=\linewidth]{../figures/individ_figs/desc09-map_ptotinc_cz90imputed_lawyers.pdf}
	\end{subfigure}

	\end{figure}
	tex*/
	texdoc close 

*****************************************************************
*** Figure E.7: Event Study: Subsamples of Physician Movers 

	texdoc init "figs_geotwfeeventstudy_subsamples", replace 
	/*tex
	\begin{landscape}
	\begin{figure}[ht]
		\centering
		\caption{\bf Event Study: Subsamples of Physician Movers} \label{fig:figs_geotwfe_eventstudy_samples} 
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:geotwfe_eventstudy_pcpdocs} Primary Care Physicians}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe01-eventstudy_PCPDOCS.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:geotwfe_eventstudy_special} Specialists}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe01-eventstudy_SPECIAL.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:geotwfe_eventstudy_ranked} MD Program Ranked by U.S. News}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe01-eventstudy_RANKED.pdf}
	\end{subfigure}
	\begin{subfigure}{0.45\linewidth}
		\caption{\label{fig:geotwfe_eventstudy_nonranked} MD Program not Ranked by U.S. News}
		\includegraphics[width=\linewidth]{../figures/individ_figs/geotwfe01-eventstudy_NONRANKED.pdf}
	\end{subfigure}

	\end{figure}
	\end{landscape}
	tex*/
	texdoc close 

******************************************************************
*** Figure E.8: Firm and Individual Fixed Effects 

	texdoc init "figs_binscatter_firmsorting", replace 
	/*tex
	\begin{figure}[ht]
		\centering
		\caption{\bf Firm and Individual Fixed Effects} \label{fig:binscatter_firmsorting} 
	\begin{subfigure}{0.8\linewidth}
		\caption{\label{fig:binscatter_firmsorting1} Unconditional}
		\includegraphics[width=\linewidth]{../figures/individ_figs/firmtwfe01-Individual_vs_firm_FE_residyear.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.8\linewidth}
		\caption{\label{fig:binscatter_firmsorting2} Within Commuting Zone}    
		\includegraphics[width=\linewidth]{../figures/individ_figs/firmtwfe01-Individual_vs_firm_FE_residczyear.pdf}
	\end{subfigure}
	\end{figure}
	tex*/
	texdoc close

*****************************************************************
*** Figure E.9: Distribution of RVU Changes

	texdoc init "figs_hist_rvu_chg", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:hist_rvu_ch} \bf Distribution of RVU Changes}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/govtpolicy01-kden_Dlog_rvus_iv_atfixq_doc_year_age40to55.pdf}
	\end{figure}
	tex*/
	texdoc close 

****************************************************************
*** Figure E.10: Effects of Changes in Medicare RVUs

	texdoc init "figs_coefplot_rvu.tex", replace
	/*tex
	\begin{figure}[!ht] \centering
		\caption{\label{fig:coefplot_rvu} \bf Effects of Changes in Medicare RVUs}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/govtpolicy01-RVU_Regressions.pdf}
	\end{figure}
	tex*/ 

****************************************************************
*** Figure E:11: Geographic Variation in Share Uninsured

	texdoc init "figs_cty_uninsured_rates.tex", replace
	/*tex
	\begin{figure}[ht]
		\centering
		\caption{\label{app_fig:aca_exposure} \bf Geographic Variation in Share Uninsured}
	\begin{subfigure}{0.8\linewidth}
		\caption{\label{app_fig:uninsured} Share of Population Under 65 Uninsured in 2013}
		\includegraphics[width=\linewidth]{../figures/individ_figs/uninsuredmap_2013_balanced.pdf}
	\end{subfigure}
	\vspace{-10pt}
	\begin{subfigure}{0.8\linewidth}
	\caption{\label{app_fig:uninsureddiff} Change in Share of Population Under 65 Insured from 2013-2017}
		\includegraphics[width=\linewidth]{../figures/individ_figs/uninsuredmap_diff_2013_2017_balanced.pdf}
	\end{subfigure}
	\end{figure}
	tex*/ 

*****************************************************************
*** Figure E:12 Implicity Subsidy vs. Log Median Household Income

	texdoc init "figs_fe_cz_gaf_diff_czchar", replace
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:figs_medinc_gaf_diff} \bf Implicit Subsidies vs. Log Median Household Income }
		\includegraphics[width=\linewidth]{../figures/individ_figs/govtpolicy01-binscatter_gaf_diff_med_hhinc2016.pdf}
	\end{figure}
	tex*/
	texdoc close

******************************************************************************
*** Figure E:13: Increase Internal Medicine Income to Dermatology Level (2SLS)

	texdoc init "figs_counterfactuals_imsameasderm2sls.tex", replace 
	/*tex
	\begin{figure}[h!] \centering
		\caption{\label{fig:cf_stpdfcore_spec5_imsameasderm_2sls} \bf Increase Internal Medicine Income to Dermatology Level (2SLS)}
		\includegraphics[width=1\linewidth]{../figures/individ_figs/counterfactuals_imsameasderm2sls.pdf}
	\end{figure}
	tex*/
	texdoc close

